package com.winchain.chainbill.bill.biz.contract.rx;

import com.shell.framework.command.ChainBase;
import com.shell.framework.command.CommandContext;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import com.winchain.chainbill.bill.biz.contract.cmd.ContractSignCmd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ContractSignSubscriber<T> extends OnErrorNotImplementedSubscriber<BillEvent<T>> {
	@Autowired
	private ContractSignCmd<T> contractSignCmd;

	public void onApplicationEvent(BillEvent<T> billEvent) {
		CommandContext<Bill<T>> context = new CommandContext();
		context.setSource(billEvent.getBill());
		context.setValue("phoneCode", billEvent.getStringValue("phoneCode"));
		context.setValue("location", billEvent.getStringValue("location"));
		context.setValue("isNotNeedAprv", billEvent.getValue("isNotNeedAprv"));
		ChainBase<Bill<T>> crb = new ChainBase();
		crb.add(this.contractSignCmd);
		crb.execute(context);
	}
}
